package pool.process;

import java.util.Hashtable;
import pool.bean.Bean;
import pool.tablename.SubPool;

import smsBean.SmsBean;
import smsBean.SubSmsBean;

import utility.CapitalChar;
//import utility.ConvertToLower;

/**
 * @author abc
 * View class which implements Process interface.
 * */
public class View implements Process 
{	
	/**
	 * setObject() method takes parameter like:
	 * @param subObject which is SubPool's object and intake make a call to getInsert() method of respective class in pool package.  
	 */
	public Hashtable<Object, Object> setObject(SubPool subObject) 
	{
		Hashtable<Object,Object> tempHash = new Hashtable<Object,Object>();
		//tempHash.putAll(subObject.initialize());
//		tempHash.putAll(subObject.setPreprocess());
//		tempHash.putAll(ConvertToLower.convertHashKey(tempHash));
		
			StringBuffer strBuf = new StringBuffer();
			tempHash.clear();
			strBuf.append(subObject.getView());
			tempHash.put("Result", strBuf.toString());
		return tempHash;		
	}


	@SuppressWarnings("unchecked")
	public Hashtable<Object, Object> setSmsObject(SubSmsBean subObject,String request) 
	{	 
		 StringBuffer strBuf = new StringBuffer();
		 strBuf = subObject.initializeToView();
		 
		 try
			{
				Class C = Class.forName("pool.bean."+CapitalChar.makeFirstCharCapital(request)+"_Bean") ;
				Bean beanObject=(Bean)C.newInstance();
				
				beanObject.setDBManager(subObject.getDBManager());
				beanObject.setReqParam(subObject.getReqParam());
				beanObject.setProcess(subObject.getProcess());	
				beanObject.setHashtable(subObject.getHashtable());
				beanObject.setViewHashtable(subObject.getViewHashtable());
				beanObject.setPropertyViewHashtable(subObject.getPropertyViewHashtable());		
				beanObject.setPropertyVector(subObject.getPropertyVector());
				//set for transaction class
				beanObject.setTransDetailsViewHashtable(subObject.getTransDetailsViewHashtable());
				Class c = Class.forName("smsBean.Sms"+CapitalChar.makeFirstCharCapital(request)) ;
				SmsBean smsbeanobject = (SmsBean)c.newInstance();
				smsbeanobject.setDBManager(subObject.getDBManager());
				smsbeanobject.setRequestParameter(subObject.getReqParam());
				strBuf.append(smsbeanobject.generatesms(beanObject.view()));
				
				
				
			}
			catch (Exception e) 
			{
				e.printStackTrace();
			}	
		Hashtable<Object,Object> tempHash = new Hashtable<Object,Object>();	
		tempHash.put("Result", strBuf.toString());
		
		return tempHash;
	}
}